<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/2
 * Time: 11:13
 */
namespace app\common\controller;
use think\Controller;
use app\common\Auth;

class BaseController extends Controller{
    protected  function checkAuth(){
        $auth=new Auth(session('uid'));
        $rule_name=request()->module().'/'.request()->controller().'/'.request()->action();
        $rule_name = strtolower($rule_name);
        $result=$auth->check($rule_name);
        return $result;
    }

    public function ajaxReturn($code=200,$data=null,$msg="")
    {
        $arr = ["code" => $code, "data" => $data, "msg" => $msg];
        return json($arr);
    }

    public function authAjaxReturn($code=200,$data=null,$msg="")
    {
        if(!$this->checkAuth()){
            return $this->ajaxReturn(500,null,"权限不足");
        }
        return $this->ajaxReturn($code,$data,$msg);
    }
}